package com.example.online_exam_system.config;

import com.google.code.kaptcha.servlet.KaptchaServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Servlet;
import java.util.HashMap;
import java.util.Map;

/**
 * @Classname:KaptchaConfig
 * @program:online-exam_-springboot
 * @author:ZiXuan
 * @crate:2021-11-04-12-21
 **/
@Configuration
public class KaptchaConfig {

    @Bean
    public ServletRegistrationBean registrationBean() {
        ServletRegistrationBean<Servlet> bean = new ServletRegistrationBean<>(new KaptchaServlet(), "/kaptcha");
        Map<String, String> map = new HashMap<>();
        map.put("kaptcha.border.color", "white");
        map.put("kaptcha.textproducer.char.length", "4");
        map.put("kaptcha.textproducer.font.color", "116,208,217");
//        map.put("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.FishEyeGimpy");
        map.put("kaptcha.image.width", "130");
        map.put("kaptcha.image.height", "50");

        bean.setInitParameters(map);
        return bean;
    }
}
